package com.zixi.beverage_order;

import com.zixi.beverage_order.mapper.OrderListMapper;
import com.zixi.beverage_order.mapper.OrderedProductMapper;
import com.zixi.beverage_order.mapper.ReviewMapper;
import com.zixi.beverage_order.pojo.OrderList;
import com.zixi.beverage_order.pojo.OrderedProduct;
import com.zixi.beverage_order.pojo.ReturnOrderedProduct;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class CRUD {


    @Autowired
    private OrderListMapper orderListMapper;

    @Autowired
    OrderedProductMapper orderedProductMapper;

    @Autowired
    ReviewMapper reviewMapper;

    @Test
    public void reviewTest(){
        System.out.println(reviewMapper.selectList(null));
    }

    @Test
    public void selectOL() {
        OrderList orderList = new OrderList();
        orderList.setPacked(true);
        orderList.setAddress("12312312321");
        orderList.setCustomerId(18L);
        System.out.println(orderList);
        orderListMapper.insert(orderList);
//        System.out.println("usermapper 返回值 ： "+temp);
        System.out.println(orderList.getId());
    }

    @Test
    public void orderedProductInsert() {
        OrderedProduct orderedProduct = new OrderedProduct();
        orderedProduct.setOrderListId(1376799288326717442L);
        orderedProduct.setProductId(1L);
        orderedProduct.setTemperature(-1);
        orderedProduct.setSweetness(2);
        orderedProductMapper.insert(orderedProduct);
        System.out.println(orderedProduct);
    }

    @Test
    public void getOneOrderListAllProduct() {
        Map<String, Object> map = new HashMap<>();
        map.put("order_list_id", 1376852695955554306L);
        List<OrderedProduct> list = orderedProductMapper.selectByMap(map);
        List<ReturnOrderedProduct> returnShoppingtrolleyList = new ArrayList<ReturnOrderedProduct>();
        for(OrderedProduct n: list){
            ReturnOrderedProduct returnOrderedProduct = new ReturnOrderedProduct(n.getId().toString(),n.getOrderListId().toString(),n.getProductId(),n.getTemperature(),n.getSweetness());
            returnShoppingtrolleyList.add(returnOrderedProduct);
        }
        System.out.println(returnShoppingtrolleyList);
    }

    @Test
    public void updataOrderedProduct(){
        OrderedProduct orderedProduct = new OrderedProduct(1L,1377188190334013441L,1L,-10,40);
        orderedProductMapper.updateById(orderedProduct);
    }

    @Test
    public void selectOrderList(){
        Map<String,Object> map = new HashMap<>();
        map.put("customer_id",4);
        map.put("finishtime",null);
        List<OrderList> allOrderLists = orderListMapper.selectByMap(map);
        System.out.println(allOrderLists);
    }
}
